package com.be.beadmin.basicData.repository;

import com.be.beadmin.basicData.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

@Repository
public interface RoleRepository  extends JpaRepository<Role,String>, JpaSpecificationExecutor<Role> {

    Role findRoleByNameAndDelete(String name, Integer delete);

    Role findRoleById(String id);


    Set<Role> findRolesByDeleteAndIdIn(Integer isDelete, List<String> ids);

    Role findRoleByCodeAndDelete(String code, Integer isDelete);


    List<Role> findRolesByDelete(Integer isDelete);

    @Query(value = "select r.name from sys_role r where r.is_delete = ?1 and r.name not in ?2", nativeQuery = true)
    List<String> findRoleNamesByDelete(Integer isDelete, List<String> notInName);

    /**
     * 根据权限id查询对应的权限类型
     */
    String findAuthorityById(String roleId);

}
